package com.bytz.modules.cms.c4c.sync;

import com.bytz.modules.cms.c4c.model.*;
import feign.Response;
import io.swagger.annotations.ApiOperation;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@FeignClient(
        name = "c4c-api",
        url = "${c4c-api.base-url}",
        path = "${c4c-api.base-path}",
        configuration = C4cBaseAuthRequestInterceptor.class
)
public interface C4cOdataFeign {

    @ApiOperation("获取token")
    @RequestMapping(value = "/$metadata", method = RequestMethod.GET)
    Response getToken(@RequestHeader(value = "x-csrf-token", defaultValue = "Fetch") String token);

    @ApiOperation("获取c4c终端用户、soldTo、shipTo")
    @RequestMapping(value = "/CorporateAccountCollection", method = RequestMethod.GET)
    C4cResponse<List<C4cCustomer>> getCorporateAccountCollection(@RequestParam("$format") String format,
                                                                 @RequestParam("$select") String select,
                                                                 @RequestParam("$filter") String filter,
                                                                 @RequestParam("$skiptoken") String skipToken);

    @ApiOperation("保存一条opportunity")
    @RequestMapping(value = "/OpportunityCollection", method = RequestMethod.POST)
    C4cXmlOpportunityResponse postOpportunityCollection(@RequestBody C4cOpportunity opportunity);

    @ApiOperation("保存一条报价单")
    @RequestMapping(value = "/SalesQuoteCollection", method = RequestMethod.POST)
    C4cXmlSalesQuoteResponse postSalesQuoteCollection(@RequestBody C4cSalesQuote salesQuote);

    @ApiOperation("根据 C4C AccountID 获取联系人")
    @RequestMapping(value = "/ContactCollection", method = RequestMethod.GET)
    C4cResponse<List<C4cGetContacts>> getContactCollection(@RequestParam(value = "$select", defaultValue = "ContactID,AccountID,Name,Email,Phone,Mobile") String select,
                                          @RequestParam("$filter") String filter,
                                          @RequestParam(value = "$format", defaultValue = "json") String format);

    @ApiOperation("根据报价单id查询报价中Y2或Y3类型的销售")
    @RequestMapping(value = "/SalesQuotePartyCollection", method = RequestMethod.GET)
    C4cResponse<List<C4cY2OrY3Sales>> getSalesQuotePartyCollection(@RequestParam(value = "$select", defaultValue = "ObjectID,QuoteID,PartyID,RoleCodeText") String select,
                                                                   @RequestParam("$filter") String filter,
                                                                   @RequestParam(value = "$format", defaultValue = "json") String format);

    @ApiOperation("获取c4c终端用户 中文名")
    @RequestMapping(value = "/CorporateAccountInternationalVersionCollection", method = RequestMethod.GET)
    C4cResponse<List<C4cChineseName>> getQueryChineseName(@RequestParam("$select") String select,
                                                          @RequestParam("$filter") String filter,
                                                          @RequestParam("$skiptoken") String skipToken,
                                                          @RequestParam("$format") String format);

    @ApiOperation("修改Y2或Y3销售")
    @RequestMapping(value = "/SalesQuotePartyCollection('{objectId}')", method = RequestMethod.PATCH)
    C4cXmlCreateY2Response patchUpdateY2OrY3(@PathVariable("objectId") String objectId, @RequestBody C4cY2OrY3Sales c4CY2OrY3Sales);


    @ApiOperation("项目订单 将机会和项目订单进行关联")
    @RequestMapping(value = "/SalesQuoteCollection('{objectId}')/SalesQuoteReference", method = RequestMethod.POST)
    C4cXmlCreateY2Response postRelationQuoteOpportunity(@PathVariable("objectId") String objectId, @RequestBody C4cQuoteOpportunity c4cQuoteOpportunity);

    @ApiOperation("在报价单中创建产品行")
    @RequestMapping(value = "/SalesQuoteCollection('{objectId}')/SalesQuoteItem", method = RequestMethod.POST)
    C4cXmlOrderItemResponse postCreateProduct(@PathVariable("objectId") String objectId, @RequestBody C4cOrderItem c4cOrderItem);

    @ApiOperation("根据条件查询opportunity")
    @RequestMapping(value = "/OpportunityCollection", method = RequestMethod.GET)
    C4cResponse<List<C4cOpportunity>> getOpportunityCollection(@RequestParam("$format") String format,
                                                               @RequestParam("$select") String select,
                                                               @RequestParam("$filter") String filter);

    @ApiOperation("更新opportunity")
    @RequestMapping(value = "/OpportunityCollection('{objectId}')", method = RequestMethod.PATCH)
    void patchOpportunityCollection(@PathVariable("objectId") String objectId, @RequestBody C4cOpportunity opportunity);

    @ApiOperation("根据c4c报价id查询 sap报价id(RelationshipRoleCode eq '6') 和 C4C Order ID(RelationshipRoleCode eq '2') ")
    @RequestMapping(value = "/SalesQuoteReferenceCollection", method = RequestMethod.GET)
    C4cResponse<List<C4cSalesQuoteReference>> getSalesQuoteReferenceCollection(@RequestParam("$format") String format,
                                                                               @RequestParam("$select") String select,
                                                                               @RequestParam("$filter") String filter);

    @ApiOperation("根据条件查询报价相关信息")
    @RequestMapping(value = "/OpportunityBusinessTransactionDocumentReferenceCollection", method = RequestMethod.GET)
    C4cResponse<List<C4cBusinessTransaction>> getBusinessTransactionCollection(@RequestParam("$format") String format,
                                                                               @RequestParam("$select") String select,
                                                                               @RequestParam("$filter") String filter);

    @ApiOperation("根据c4cOrderId查询SAP Order ID")
    @RequestMapping(value = "/CustomerOrderBusinessTransactionDocumentReferenceCollection", method = RequestMethod.GET)
    C4cResponse<List<C4cBusinessTransactionDocument>> getSapOrder(@RequestParam("$format") String format,
                                                                  @RequestParam("$select") String select,
                                                                  @RequestParam("$filter") String filter);


}
